package uk.org.landeg.euler.problems;

import java.math.BigInteger;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;


public class Problem057 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem057());
		launcher.solve();
	}

	@Override
	public Object solve() {
		BigInteger nt, dt;
		BigInteger n = BigInteger.valueOf(3),
				d = BigInteger.valueOf(2);
		final BigInteger TWO = BigInteger.valueOf(2);
		int it = 1, dLen, nLen;
		int count = 0;
		String nStr, dStr;
		
		StringBuilder sb = new StringBuilder();
		while (it <= 1000) {
			nStr = n.toString();
			dStr = d.toString();
			nLen = nStr.length();
			dLen = dStr.length();
			
			if (nLen > dLen) {
				count++;
			}
			
//			sb.append(it)
//				.append("\t")
//				.append(nStr.length())
//				.append("/")
//				.append(dStr.length())
//				.append("\t")
//				.append(nStr)
//				.append("/")
//				.append(dStr);
//			System.out.println(sb.toString());
//			sb.setLength(0);
			dt = n.add(d);
			nt = d.add(dt.multiply(TWO));
			n = d.add(dt);
			d = dt;
			it++;
		}
		return count;
	}

	@Override
	public String getDescription() {
		return "In the first one-thousand expansions, " +
				"how many fractions contain a numerator " +
				"with more digits than denominator?";
	}

	@Override
	public Integer getProblemNumber() {
		return 57;
	}
}
